﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace Validation
{
    public class AgeValidationRule : ValidationRule
    {
        public int MinAge { get; set; }
        public int MaxAge { get; set; }
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            int age;
            try
            {
                age = int.Parse(value.ToString());
            }
            catch (Exception)
            {
                return new ValidationResult(false, "age error");
            }

            if (age < MinAge || age > MaxAge)
                return new ValidationResult(false, "age error");
            return new ValidationResult(true, string.Empty);
        }
    }
}
